var app = new Vue({
    el: '#app',
    data: {
        form: {},
        canSubmit: false
    },
    methods: {
        submit: function() {
            var _this = this;
            if (!_this.form.username) {
                _this.$message.error('请输入账号');
                return false;
            }
            if (!_this.form.password) {
                _this.$message.error('请输入密码');
                return false;
            }
            _this.canSubmit = true;
            $.ajax({
                url: '/login/login',
                type: 'post',
                data: _this.form,
                dataType: 'json',
                success: function(res) {
                    if (res.status === 0) {
                        window.location.href = '/short/list'
                    } else {
                        _this.$message.error(res.message)
                    }
                    _this.canSubmit = false;
                }
            })
        }
    }
});

$(document).keyup(function(e){
    var key = e.which;
    if(key==13){
        app.submit();
        return false;
    }
});
